package com.example.mountainwalker.mapper;

import com.example.mountainwalker.entity.ScenicLikeInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ScenicLikeMapper {
    @Select("SELECT sl.scenic_like_id as scenic_like_id, " +  // 修改别名
            "sl.user_id as user_id, " +                      // 修改别名
            "sl.scenic_spot_id as scenic_spot_id, " +        // 修改别名
            "sl.like_time as like_time, " +                  // 修改别名
            "u.user_name as user_name, " +                   // 修改别名
            "ss.scenic_area_name as scenic_area_name " +               // 修改别名
            "FROM scenic_like sl " +
            "LEFT JOIN user_info u ON sl.user_id = u.user_id " +
            "LEFT JOIN scenic_spot ss ON sl.scenic_spot_id = ss.scenic_spot_id")
    List<ScenicLikeInfo> getScenicLikeInfo();

    @Select("SELECT sl.scenic_like_id as scenic_like_id, " +  // 修改别名
            "sl.user_id as user_id, " +                       // 修改别名
            "sl.scenic_spot_id as scenic_spot_id, " +         // 修改别名
            "sl.like_time as like_time, " +                   // 修改别名
            "u.user_name as user_name, " +                    // 修改别名
            "ss.scenic_area_name as scenic_area_name " +                // 修改别名
            "FROM scenic_like sl " +
            "LEFT JOIN user_info u ON sl.user_id = u.user_id " +
            "LEFT JOIN scenic_spot ss ON sl.scenic_spot_id = ss.scenic_spot_id " +
            "WHERE sl.scenic_like_id = #{id}")
    ScenicLikeInfo getScenicLikeInfoById(Integer id);

    @Delete("DELETE FROM scenic_like WHERE scenic_like_id = #{id}")
    int deleteScenicLikeInfoById(Integer id);

    @Insert("INSERT INTO scenic_like (user_id, scenic_spot_id, like_time) " +
            "VALUES (#{user_id}, #{scenic_spot_id}, #{like_time})")  // 修改参数名
    @Options(useGeneratedKeys = true, keyProperty = "scenic_like_id") // 修改keyProperty
    int insertScenicLikeInfo(ScenicLikeInfo scenicLikeInfo);
}